<template>
  <div>


    <Form ref="formInline" inline>
      <!--<Button type="primary" class="fl" icon="plus" @click="add">增加用户</Button>-->

    </Form>


    <Tabs>
      <TabPane label="项目信息">
        <Form ref="companyInfo" :model="companyInfo" :label-width="250" :rules="ruleInline">
          <FormItem label="项目名称" prop="title">
            <Input v-model="companyInfo.title" placeholder="项目名称"></Input>
          </FormItem>
          <FormItem label="公司地址" prop="address">
            <Input v-model="companyInfo.address" placeholder="公司地址"></Input>
          </FormItem>
          <FormItem label="银行账号" prop="builder">
            <Input v-model="companyInfo.bank_account" placeholder="银行账号"></Input>
          </FormItem>

          <FormItem label="开户银行" prop="leader_builder">
            <Input v-model="companyInfo.bank_name" placeholder="开户银行"></Input>
          </FormItem>

          <FormItem label="公司账号（三证）" prop="operators">
            <Input v-model="companyInfo.account" placeholder="公司账号（三证）"></Input>
          </FormItem>

          <FormItem>
            <Button type="primary" @click="post('companyInfo',companyInfo)">保存</Button>
          </FormItem>
        </Form>
      </TabPane>
    </Tabs>


  </div>
</template>
<script>
  import {company} from "@/api/supervision";
  import {
    Button,
    DatePicker,
    Form,
    FormItem,
    Input,
    InputNumber,
    Modal,
    Option,
    Radio,
    RadioGroup,
    Select,
    TabPane,
    Tabs,
    Tag
  } from "iview";
  //import {mapGetters} from "vuex";

  export default {
    components: {
      InputNumber,
      Button,
      Form,
      FormItem,
      Input,
      Tabs,
      TabPane,
      RadioGroup,
      Radio,
      Select,
      Option,
      Tag,
      Modal,
      DatePicker
    },
    data() {
      return {
        companyInfo: {
          id: '',
          title: '',
        },
        ruleInline: {
          title: [{required: true, message: "必须填写公司名称", trigger: "blur"}],
          address: [{required: true, message: "必须填写公司地址", trigger: "blur"}],
        },
      };
    },
    methods: {
      post(type, data) {

        if(type === 'companyInfo') {
          this.$refs["companyInfo"].validate(valid => {
            if(valid) {

              if(data.id) {
                //更新数据
                company.update(data.id, data).then(res => {
                  if(res.errno !== 0) {
                    this.$Message.error(res.errmsg);
                  } else {
                    this.$router.push("/supervision/company/list");
                  }
                });
              } else {
                //新增数据
                company.create(data).then(res => {
                  if(res.errno !== 0) {
                    this.$Message.error(res.errmsg);
                  } else {
                    this.$router.push("/supervision/company/list");
                  }
                });
              }
            } else {
              this.$Message.error("请填写必要信息");
            }
          });
        }
      },
      get(id) {
        company.getInfo(id, {}).then(res => {
          this.companyInfo = res.data;
        });
      },
    },
    computed: {
      //...mapGetters(["getUser"])
    },
    mounted() {
      if(this.$route.query.id) {
        this.get(this.$route.query.id);
      }
    }
  };
</script>
